package com.isitandroid.coldfireteamapp;



import android.os.Handler;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;


class SplashScreenThread extends Thread {
	
	private static final int SPLASH_SCREEN_DURATION = 1500;
	private static final int SPLASH_SCREEN_FADE_OUT_DURATION = 1500;
	private SplashScreenThread splashTread;

	private RelativeLayout splashLayout;
	private RelativeLayout mainLayout;
	private ImageView splashLogo;
	


	/*
	 * Class members
	 */
	Handler handler;

	public SplashScreenThread(Handler hdler , ImageView splashLogo, RelativeLayout splashLayout , RelativeLayout mainLayout ) {
		handler = hdler;
		this.splashLogo = splashLogo;
		this.splashLayout = splashLayout;
		this.mainLayout = mainLayout ;
		mainLayout.setVisibility(View.GONE);
	}

	@Override
	public void run() {
		try {
			synchronized (this) {
				// Wait given period of time
				wait(SPLASH_SCREEN_DURATION);
			}

		} catch (InterruptedException e) {
			// do nothing
		}

		handler.post(new Runnable() {
			public void run() {
				{
					startSplashScreenFadeOut();

				}

			}
		});
	}
	private void startSplashScreenFadeOut() {
		AnimationSet animationSet = new AnimationSet(true);
		Animation alphaAnimation = new AlphaAnimation(1, 0);
		animationSet.addAnimation(alphaAnimation);
		animationSet.setFillAfter(true);
		animationSet.setDuration(SPLASH_SCREEN_FADE_OUT_DURATION);
		animationSet.setAnimationListener((new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {

			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				splashLayout.setVisibility(View.GONE);
				mainLayout.setVisibility(View.VISIBLE);
				
			}
		}));
		splashLogo.startAnimation(animationSet);
	}
}



